<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
	<title>null_value | ElasticSearch 7.7 权威指南中文版</title>
	<meta name="keywords" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <meta name="description" content="ElasticSearch 权威指南中文版, elasticsearch 7, es7, 实时数据分析，实时数据检索" />
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
	<link rel="stylesheet" type="text/css" href="../static/styles.css" />
	<script>
	var _link = 'null-value.html';
    </script>
</head>
<body>
<div class="main-container">
    <section id="content">
        <div class="content-wrapper">
            <section id="guide" lang="zh_cn">
                <div class="container">
                    <div class="row">
                        <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                            <div style="color:gray; word-break: break-all; font-size:12px;">原英文版地址: <a href="https://www.elastic.co/guide/en/elasticsearch/reference/7.7/null-value.html" rel="nofollow" target="_blank">https://www.elastic.co/guide/en/elasticsearch/reference/7.7/null-value.html</a>, 原文档版权归 www.elastic.co 所有<br/>本地英文版地址: <a href="../en/null-value.html" rel="nofollow" target="_blank">../en/null-value.html</a></div>
                        <!-- start body -->
                  <div class="page_header">
<strong>重要</strong>: 此版本不会发布额外的bug修复或文档更新。最新信息请参考 <a href="https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html" rel="nofollow">当前版本文档</a>。
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="mapping.html">Mapping</a></span>
»
<span class="breadcrumb-link"><a href="mapping-params.html">Mapping parameters</a></span>
»
<span class="breadcrumb-node"><code class="literal">null_value</code></span>
</div>
<div class="navheader">
<span class="prev">
<a href="norms.html">« <code class="literal">norms</code></a>
</span>
<span class="next">
<a href="position-increment-gap.html"><code class="literal">position_increment_gap</code> »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="null-value"></a><code class="literal">null_value</code><a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/mapping/params/null-value.asciidoc">edit</a>
</h2>
</div></div></div>
<p>A <code class="literal">null</code> value cannot be indexed or searched.  When a field is set to <code class="literal">null</code>,
(or an empty array or an array of <code class="literal">null</code> values)  it is treated as though that
field has no values.</p>
<p>The <code class="literal">null_value</code> parameter allows you to replace explicit <code class="literal">null</code> values with
the specified value so that it can be indexed and searched.  For instance:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT my_index
{
  "mappings": {
    "properties": {
      "status_code": {
        "type":       "keyword",
        "null_value": "NULL" <a id="CO352-1"></a><i class="conum" data-value="1"></i>
      }
    }
  }
}

PUT my_index/_doc/1
{
  "status_code": null
}

PUT my_index/_doc/2
{
  "status_code": [] <a id="CO352-2"></a><i class="conum" data-value="2"></i>
}

GET my_index/_search
{
  "query": {
    "term": {
      "status_code": "NULL" <a id="CO352-3"></a><i class="conum" data-value="3"></i>
    }
  }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/773.console"></div>
<div class="calloutlist">
<table border="0" summary="Callout list">
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO352-1"><i class="conum" data-value="1"></i></a></p>
</td>
<td align="left" valign="top">
<p>Replace explicit <code class="literal">null</code> values with the term <code class="literal">NULL</code>.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO352-2"><i class="conum" data-value="2"></i></a></p>
</td>
<td align="left" valign="top">
<p>An empty array does not contain an explicit <code class="literal">null</code>, and so won’t be replaced with the <code class="literal">null_value</code>.</p>
</td>
</tr>
<tr>
<td align="left" valign="top" width="5%">
<p><a href="#CO352-3"><i class="conum" data-value="3"></i></a></p>
</td>
<td align="left" valign="top">
<p>A query for <code class="literal">NULL</code> returns document 1, but not document 2.</p>
</td>
</tr>
</table>
</div>
<div class="important admon">
<div class="icon"></div>
<div class="admon_content">
<p>The <code class="literal">null_value</code> needs to be the same datatype as the field.  For
instance, a <code class="literal">long</code> field cannot have a string <code class="literal">null_value</code>.</p>
</div>
</div>
<div class="note admon">
<div class="icon"></div>
<div class="admon_content">
<p>The <code class="literal">null_value</code> only influences how data is indexed, it doesn’t modify
the <code class="literal">_source</code> document.</p>
</div>
</div>
</div>
<div class="navfooter">
<span class="prev">
<a href="norms.html">« <code class="literal">norms</code></a>
</span>
<span class="next">
<a href="position-increment-gap.html"><code class="literal">position_increment_gap</code> »</a>
</span>
</div>
</div>

                  <!-- end body -->
                        </div>
                        <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                        
                        </div>
                    </div>
                </div>
            </section>
        </div>
    </section>
</div>
<script src="../static/cn.js"></script>
</body>
</html>